﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Milkify.ComponentModel
{
    public class TaskUrlConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            if (value is string)
                return new Uri((string)value, UriKind.RelativeOrAbsolute);
            if (value is Uri)
                return (Uri)value;
            throw new NotSupportedException(string.Format("Don't know how to convert value of type '{0}' to type 'System.Uri'.", value.GetType()));
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            if (value is Uri && targetType == typeof(string))
                return ((Uri)value).ToString();
            throw new NotSupportedException(string.Format("Don't know how to convert value of type '{0}' to type '{1}'.", value.GetType(), targetType));
        }

        #endregion
    }
}
